package BeanUtils.T5;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.List;

public class T5 {

    public static void main(String[] args) throws DocumentException {
        ArrayList<Student>list = new ArrayList<>();

        SAXReader sr = new SAXReader();
        Document doc = sr.read("BeanUtils/T5/student.xml");
        Element rootElement = doc.getRootElement();
        List<Element> elements = rootElement.elements();
        for (Element element : elements) {
            Student s = new Student();
            s.setStuNo(element.attributeValue("stuNo"));
            s.setName(element.elementText("name"));
            s.setAge(Integer.parseInt(element.elementText("age")));
            s.setSex(element.elementText("sex"));
            s.setScore(Integer.parseInt(element.elementText("score")));
            list.add(s);
        }

        for (Student s : list) {
            System.out.println(s);
        }
    }
}
